package com.linkage.seapeak.activity.message;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatCheckBox;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;

import com.linkage.jz.bankruptcy.R;
import com.linkage.seapeak.base.BaseWhiteActivity;
import com.linkage.seapeak.pojo.VoteGroup;

/**
 * 群发消息选择人员的筛选页
 */
public class ScreenUserActivity extends BaseWhiteActivity {

    private RadioGroup committee;
    private RadioGroup onlineStatus;
    private AppCompatCheckBox kindOrdinary;
    private AppCompatCheckBox kindGuarantee;
    private AppCompatCheckBox kindOther;
    private AppCompatCheckBox kindTax;
    private EditText minAmountDeclared;
    private EditText maxAmountDeclared;
    private EditText minConfirmAmount;
    private EditText maxConfirmAmount;
    private AppCompatCheckBox progressStatus0;
    private AppCompatCheckBox progressStatus1;
    private AppCompatCheckBox progressStatus2;
    private AppCompatCheckBox progressStatus3;
    private AppCompatCheckBox progressStatus4;
    private AppCompatCheckBox progressStatus5;
    private AppCompatCheckBox progressStatus6;
    private AppCompatCheckBox progressStatus7;
    private AppCompatCheckBox progressStatus8;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen_user, "成员筛选");

        initView();

        findViewById(R.id.target_1).setVisibility(View.VISIBLE);
        findViewById(R.id.target_2).setVisibility(View.VISIBLE);
        findViewById(R.id.target_3).setVisibility(View.GONE);
        findViewById(R.id.target_4).setVisibility(View.GONE);
        committee.check(R.id.target_1);

        String seltype = "";
        try {
            seltype = getIntent().getStringExtra("seltype");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (seltype != null)
        {
            if("1".equalsIgnoreCase(seltype))
            {
                progressStatus0.setVisibility(View.GONE);
                progressStatus1.setVisibility(View.GONE);
                progressStatus2.setVisibility(View.GONE);
                progressStatus3.setVisibility(View.GONE);
                progressStatus4.setVisibility(View.GONE);
            }
        }


        addMenu(new MenuAction(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                if (committee.getCheckedRadioButtonId() == R.id.target_1)
                    intent.putExtra("committee", 1);
                else if (committee.getCheckedRadioButtonId() == R.id.target_2)
                    intent.putExtra("committee", 2);
                else if (committee.getCheckedRadioButtonId() == R.id.target_3)
                    intent.putExtra("committee", 3);
                else if (committee.getCheckedRadioButtonId() == R.id.target_4)
                    intent.putExtra("committee", 4);

                int online = 0;
                if (onlineStatus.getCheckedRadioButtonId() == R.id.status_mid)
                    online = 1;
                if (onlineStatus.getCheckedRadioButtonId() == R.id.status_right)
                    online = 2;
                intent.putExtra("onlineStatus", online);
                intent.putExtra("kindTax", kindTax.isChecked());
                intent.putExtra("kindGuarantee", kindGuarantee.isChecked());
                intent.putExtra("kindOther", kindOther.isChecked());
                intent.putExtra("kindOrdinary", kindOrdinary.isChecked());
                try {
                    intent.putExtra("minAmountDeclared", Double.valueOf(minAmountDeclared.getText().toString()));
                } catch (Exception e){
                    intent.putExtra("minAmountDeclared", 0f);
                }
                try {
                    intent.putExtra("maxAmountDeclared", Double.valueOf(maxAmountDeclared.getText().toString()));
                } catch (Exception e){
                    intent.putExtra("maxAmountDeclared", 0f);
                }
                try {
                    intent.putExtra("minConfirmAmount", Double.valueOf(minConfirmAmount.getText().toString()));
                } catch (Exception e){
                    intent.putExtra("minConfirmAmount", 0f);
                }
                try {
                    intent.putExtra("maxConfirmAmount", Double.valueOf(maxConfirmAmount.getText().toString()));
                } catch (Exception e){
                    intent.putExtra("maxConfirmAmount", 0f);
                }
                String status = "";
                status += progressStatus0.isChecked() ? ",0" : "";
                status += progressStatus1.isChecked() ? ",1" : "";
                status += progressStatus2.isChecked() ? ",2" : "";
                status += progressStatus3.isChecked() ? ",3" : "";
                status += progressStatus4.isChecked() ? ",4" : "";
                status += progressStatus5.isChecked() ? ",5" : "";
                status += progressStatus6.isChecked() ? ",6" : "";
                status += progressStatus7.isChecked() ? ",7" : "";
                status += progressStatus8.isChecked() ? ",8" : "";
                if(!TextUtils.isEmpty(status))
                    status = status.substring(1);
                intent.putExtra("processStatus", status);
                setResult(RESULT_OK, intent);
                finish();
            }
        }, "下一步", 0));
    }

    private void initView() {
        committee = (RadioGroup) findViewById(R.id.committee);
        onlineStatus = (RadioGroup) findViewById(R.id.onlineStatus);
        kindOrdinary = (AppCompatCheckBox) findViewById(R.id.kindOrdinary);
        kindGuarantee = (AppCompatCheckBox) findViewById(R.id.kindGuarantee);
        kindOther = (AppCompatCheckBox) findViewById(R.id.kindOther);
        kindTax = (AppCompatCheckBox) findViewById(R.id.kindTax);
        minAmountDeclared = (EditText) findViewById(R.id.minAmountDeclared);
        maxAmountDeclared = (EditText) findViewById(R.id.maxAmountDeclared);
        minConfirmAmount = (EditText) findViewById(R.id.minConfirmAmount);
        maxConfirmAmount = (EditText) findViewById(R.id.maxConfirmAmount);
        progressStatus0 = (AppCompatCheckBox) findViewById(R.id.progress_status_0);
        progressStatus1 = (AppCompatCheckBox) findViewById(R.id.progress_status_1);
        progressStatus2 = (AppCompatCheckBox) findViewById(R.id.progress_status_2);
        progressStatus3 = (AppCompatCheckBox) findViewById(R.id.progress_status_3);
        progressStatus4 = (AppCompatCheckBox) findViewById(R.id.progress_status_4);
        progressStatus5 = (AppCompatCheckBox) findViewById(R.id.progress_status_5);
        progressStatus6 = (AppCompatCheckBox) findViewById(R.id.progress_status_6);
        progressStatus7 = (AppCompatCheckBox) findViewById(R.id.progress_status_7);
        progressStatus8 = (AppCompatCheckBox) findViewById(R.id.progress_status_8);
    }
}
